import {FETCH_TEST, ADD_USER, DELETE_USER} from '../constant/types';

export const fetchTest = (item) => dispatch => {
    // fetch("xxx")
    // .then(res => res.json())
    // .then(posts => dispatch({
    //     type:FETCH_POSTS,
    //     payload:posts
    // }));
    let promise = new Promise(function (resolve, reject) {
        setTimeout(() => {
            resolve(item); //代码正常执行！
        }, 1000); // 模拟1秒后promise返回
    });
    promise.then(data => dispatch({
        type: FETCH_TEST,
        payload: data
    }));
}

export const addUser = item => dispatch => {
    console.log(item);
    console.log(dispatch);
    dispatch({
        type: ADD_USER,
        payload: item
    });
}
export const deleteUser = item => dispatch => {
    console.log(item);
    console.log(dispatch);
    dispatch({
        type: DELETE_USER,
        payload: item
    });
}